///**
// * @Company: 北京慧点科技有限公司 | www.smartdot.com.cn
// * @Copyright 1998-2022 © Smartdot Technologies Co., Ltd.
// */
//
//package com.hd.rcugrc.project.leaveapplication.leave.mvc;
//
//import java.util.HashMap;
//import java.util.Map;
//
//import com.hd.rcugrc.project.leaveapplication.leave.service.WeFlowListService;
//import com.hd.rcugrc.project.leaveapplication.leave.util.flowListUtil;
//import com.itextpdf.text.log.Logger;
//import com.itextpdf.text.log.LoggerFactory;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.InitializingBean;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.support.ApplicationObjectSupport;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.RestController;
//
//import com.hd.rcugrc.bpm.User;
//import com.hd.rcugrc.bpm.facade.mobile.mvc.query.ListInfoQuery;
//import com.hd.rcugrc.bpm.facade.mobile.mvc.query.ListQueryResult;
//import com.hd.rcugrc.data.crud.criteria.Criterion;
//import com.hd.rcugrc.data.crud.criteria.OrderBy;
//import com.hd.rcugrc.security.context.AuthenticationHelper;
//import com.hd.rcugrc.security.user.UserInfoService;
//import com.hd.rcugrc.web.ws.Expression;
//import com.hd.rcugrc.web.ws.ExpressionUtils;
//
//import io.swagger.v3.oas.annotations.Operation;
//import io.swagger.v3.oas.annotations.Parameter;
//import io.swagger.v3.oas.annotations.responses.ApiResponse;
//import io.swagger.v3.oas.annotations.responses.ApiResponses;
//
///**
// * @author smartdot
// * @version 1.0 - 2024-07-15 09:35:47
// */
//@RestController("OaFlowListController")
//@RequestMapping("${url.rest.prefix.framework.v1}/flow-list1ylt")
//public class WeFlowListController extends ApplicationObjectSupport
//        implements InitializingBean {
//
//    Logger log = LoggerFactory.getLogger(WeFlowListController.class);
//    private Map<String, String> queryFieldMapping;
//    private Map<Integer, String> openModeAndFormPrefixReader;
//    @Autowired
//    private UserInfoService userInfoService;
//    @Autowired
//    private WeFlowListService weFlowListService;
//
//    @Operation(summary = "返回待处理流程列表", description = "返回指定账户下待处理流程列表信息; 可根据查询参数过滤, 排序;", tags = { "OA通用流程列表" })
//    @RequestMapping(value = "/processing", method = RequestMethod.POST)
//    @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "获取指定账户下待处理列表信息成功") })
//    public ListQueryResult getProcessingList(
//            @Parameter(name = "listInfoQuery", description = "查询待处理任务列表参数", required = true) @RequestBody ListInfoQuery listInfoQuery) {
//
//        Expression[] expressions = listInfoQuery.getExpressions();
//        String orderBy = listInfoQuery.getOrderBy();
//        OrderBy[] orders = createOrderBys(orderBy);
//        int startPosition = listInfoQuery.getStartPosition();
//        int maxResults = listInfoQuery.getMaxResults();
//        String formId = listInfoQuery.getFormId();
//        String columns = listInfoQuery.getColumns();
//        String[] columnarray = columns.split("\\,");
//        Criterion[] criterions = toWorkFlowCriterions(expressions);
//        String account = AuthenticationHelper.getCurrentUser();
//        String name = AuthenticationHelper.getUserName(account, account, this.userInfoService);
//        User owner = new User(account, name);
//        return this.weFlowListService.findActiveList(owner, formId, columnarray, criterions, startPosition, maxResults,
//                orders, false, null);
//    }
//
//    /**
//     * 返回已处理流程列表 获取指定账户下已处理列表信息
//     *
//     * @param processedInfoQuery 查询已处理列表参数
//     * @return 返回已处理流程列表
//     */
//    @Operation(summary = "返回已处理流程列表", description = "返回指定账户下已处理流程列表信息; 可根据查询参数过滤, 排序;", tags = { "OA通用流程列表" })
//    @RequestMapping(value = "/processed", method = RequestMethod.POST)
//    @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "获取指定账户下已处理列表信息成功") })
//    public ListQueryResult getProcessedList(
//            @Parameter(name = "listInfoQuery", description = "查询待处理任务列表参数", required = true) @RequestBody ListInfoQuery listInfoQuery) {
//
//        Expression[] expressions = listInfoQuery.getExpressions();
//        String orderBy = listInfoQuery.getOrderBy();
//        OrderBy[] orders = createOrderBys(orderBy);
//        int startPosition = listInfoQuery.getStartPosition();
//        int maxResults = listInfoQuery.getMaxResults();
//        String formId = listInfoQuery.getFormId();
//        String columns = listInfoQuery.getColumns();
//        columns = columns.replace(flowListUtil.CURRENT_STATUS, "").replace(flowListUtil.CURRENT_USER, "");
//        String[] columnarray = columns.split("\\,");
//        Criterion[] criterions = toWorkFlowCriterions(expressions);
//        String account = AuthenticationHelper.getCurrentUser();
//        String name = AuthenticationHelper.getUserName(account, account, this.userInfoService);
//        User owner = new User(account, name);
//        return this.weFlowListService.findProcessedList(owner, formId, columnarray, criterions, startPosition,
//                maxResults, orders, false, null);
//    }
//
//    /**
//     * 返回已办结流程列表 获取指定账户下已办结列表信息
//     *
//     * @param completedInfoQuery 查询已办结列表参数
//     * @return 返回待处理流程列表
//     */
//    @Operation(summary = "返回已办结流程列表", description = "返回指定账户下已办结流程列表信息; 可根据查询参数过滤, 排序;", tags = { "OA通用流程列表" })
//    @RequestMapping(value = "/completed", method = RequestMethod.POST)
//    @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "获取指定账户下已办结列表信息成功") })
//    public ListQueryResult getCompletedList(
//            @Parameter(name = "listInfoQuery", description = "查询待处理任务列表参数", required = true) @RequestBody ListInfoQuery listInfoQuery) {
//
//        Expression[] expressions = listInfoQuery.getExpressions();
//        String orderBy = listInfoQuery.getOrderBy();
//        OrderBy[] orders = createOrderBys(orderBy);
//        int startPosition = listInfoQuery.getStartPosition();
//        int maxResults = listInfoQuery.getMaxResults();
//        String formId = listInfoQuery.getFormId();
//        String columns = listInfoQuery.getColumns();
//        String[] columnarray = columns.split("\\,");
//        Criterion[] criterions = toWorkFlowCriterions(expressions);
//        String account = AuthenticationHelper.getCurrentUser();
//        String name = AuthenticationHelper.getUserName(account, account, this.userInfoService);
//        User owner = new User(account, name);
//        return this.weFlowListService.findCompletedList(owner, formId, columnarray, criterions, startPosition,
//                maxResults, orders, false, null);
//    }
//
//    /**
//     * 待办表达式在转换成查询约束条件
//     *
//     * @param expressions 表达式
//     * @return 查询约束条件
//     */
//    private Criterion[] toWorkFlowCriterions(Expression[] expressions) {
//        Criterion[] criterions;
//
//        if (expressions != null) {
//            Expression[] newExpressions = warpExpression(expressions);
//            criterions = ExpressionUtils.getCriteria(newExpressions, queryFieldMapping);
//        } else {
//            criterions = new Criterion[0];
//        }
//        return criterions;
//    }
//
//    private Expression[] warpExpression(Expression[] expressions) {
//        if (expressions == null) {
//            return expressions;
//        }
//        Expression[] expressionNews = new Expression[expressions.length];
//        int index = 0;
//        for (Expression expression : expressions) {
//            Expression newExpression = new Expression();
//            newExpression.setDataType(expression.getDataType());
//            newExpression.setOp(expression.getOp());
//            if (expression.getDataType().equalsIgnoreCase("exps")) {
//                newExpression.setExpressionsValue(warpExpression(expression.getExpressionsValue()));
//            } else {
//                popExpression(expression, newExpression);
//            }
//            expressionNews[index++] = newExpression;
//        }
//        return expressionNews;
//    }
//
//    private void popExpression(Expression src, Expression dest) {
//        boolean isOpenMOde = "openMode".equalsIgnoreCase(src.getName());
//        if (isOpenMOde) {
//            dest.setName("formPrefix");
//            int openMode = src.getIntValue();
//            String openModeStr = src.getStringValue();
//            dest.setDataType("str");
//            dest.setStringValue(openModeToFormPrefix(openModeStr, openMode));
//        } else {
//            dest.setName(src.getName());
//            dest.setBooleanValue(src.getBooleanValue());
//            dest.setDateTimeValue(src.getDateTimeValue());
//            dest.setDateValue(src.getDateValue());
//            dest.setDoubleValue(src.getDoubleValue());
//            dest.setExpressionsValue(src.getExpressionsValue());
//            dest.setExpressionValue(src.getExpressionValue());
//            dest.setLongValue(src.getLongValue());
//            dest.setFloatValue(src.getFloatValue());
//            dest.setIntValue(src.getIntValue());
//            dest.setShortValue(src.getShortValue());
//            dest.setStringValue(src.getStringValue());
//            dest.setObjectDataValue(src.getObjectDataValue());
//        }
//    }
//
//    /**
//     * 将打开模式
//     *
//     * @return
//     */
//    private String openModeToFormPrefix(String openModeStr, int openMode) {
//        if (StringUtils.isNotBlank(openModeStr)) {
//            openMode = Integer.valueOf(openMode);
//        }
//        String prefix = openModeAndFormPrefixReader.get(openMode);
//        if (StringUtils.isBlank(prefix)) {
//            log.error("根据 openMode=" + openMode + " 转换成表单协议时，未找到相应协议，请检查是否支持该打开方式");
//            return "unknown";
//        }
//        return prefix;
//    }
//
//    /**
//     * @param orderBy
//     * @return
//     */
//    private OrderBy[] createOrderBys(String orderBy) {
//        OrderBy[] orders = null;
//        if ((orderBy != null) && (orderBy.length() > 0)) {
//            int pos = orderBy.indexOf(' ');
//            String field = orderBy.substring(0, pos);
//            if (queryFieldMapping != null && queryFieldMapping.containsKey(field)) {
//                field = queryFieldMapping.get(field);
//            }
//
//            String dir = orderBy.substring(pos + 1);
//            if ("asc".equalsIgnoreCase(dir)) {
//                orders = OrderBy.orderBy(OrderBy.asc(field));
//            } else {
//                orders = OrderBy.orderBy(OrderBy.desc(field));
//            }
//        }
//        return orders;
//    }
//
//    @Override
//    public void afterPropertiesSet() throws Exception {
//        if (queryFieldMapping == null) {
//            queryFieldMapping = new HashMap<String, String>();
//            queryFieldMapping.put("TITLE", "list_.TITLE");
//            queryFieldMapping.put("title", "list_.TITLE");
//        }
//    }
//}
